function Reestimate(DATA, PARAMS, OUT, k, version)

    close all
    format long g
    
    tolerance = 1e-12;
    
    addpath('helpers')
    addpath('rcnl_demand')
    addpath('rcnl_supply')

    basic_parameters
    
    
    [df, dfull, cdindex] = load_data_full(DATA);

    disp(['Version: ', version]);

    model = ['og', version];
    
    disp(['Model: ', model]);


    [xlinear, ~, xnonlin, fe, ~, zdemand, ~, zinside, xid] = final_variables(df, 'og', model);
    [~, ~, coefs] = load_parameters(fullfile(PARAMS, 'Replicate.mat'));
    
    s_jt     = df.s_jt;
    p_jt     = df.p_jt;
    prodid   = df.prodid;
    market   = df.cdid;
    cluster  = df.cityid;
    dresults = struct;
    Pi       = coefs.Pi; 
    rho      = coefs.rho;
    alpha    = coefs.alpha;
    par_rest = 1:3;
    varargin = {};
    
    % degree of mispecification
    K      = length(strength_D);
    smooth = strength_D(k);

    coefs_sim = struct;
    coefs_sim.dist_mis = nan;
    coefs_sim.alpha = (1-smooth*rho)*alpha/(1-rho); 

    try
        [dresults, IVDtilda] = estimate_rcnl( ...
            Pi.*smooth,      ...
            rho.*smooth,     ...
            s_jt,            ...
            p_jt,            ...
            prodid,          ...
            xlinear,         ...
            xnonlin,         ...
            zdemand,         ...
            zinside,         ...
            fe,              ...
            market,          ...
            dfull,           ...
            cluster,         ...
            "RCNL_f",        ...
            par_rest,        ...
            coefs_sim,       ...
            tolerance,       ...
            varargin{:});
        dflags = 0
    catch err
        fprintf('%s: %s\n', err.identifier, err.message);
        dflags = 1
        IVDtilda = NaN;
    end
    
    if dflags == 0
        sresults = estimate_rcnl_supply( ...
            df,                          ...
            cdindex,                     ...
            dresults,                    ...
            dresults.derMat,             ...
            IVDtilda,                    ...
            'og'                         ...
        );
    else
        sresults = struct;
    end
    
    ddedup = dfull(cdindex, :);
    
    outfile = fullfile(OUT, ['Reestimate',version,'_',int2str(k),'.mat']);
    
    save(outfile,   ...
        'df',       ...
        'ddedup',   ...
        'cdindex',  ...
        'dresults', ...
        'dflags',   ...
        'sresults'  ...
    );
    
    disp('Done.');

    % Log the shelf-space coefficient
    logFile = fullfile(OUT, ['log_shelfspace_', version, '_', int2str(k), '.txt']);
    fid = fopen(logFile, 'w');
    fprintf(fid, 'Shelf-space coefficient: %f\n', dresults.theta(end));
    fclose(fid);
    
    end
